package cyx.example.ddd.application.order.query;

import cyx.example.ddd.application.order.dto.OrderDTO;
import cyx.example.ddd.application.order.dto.OrderStatisticsDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

/**
 * 订单查询服务实现
 * 专门处理订单相关的查询操作，实现CQRS模式
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderQueryServiceImpl implements OrderQueryService {
    
    private final OrderQueryRepository orderQueryRepository;
    
    @Override
    public Optional<OrderDTO> findById(String orderId) {
        log.debug("查询订单详情，订单ID: {}", orderId);
        return orderQueryRepository.findById(orderId);
    }
    
    @Override
    public List<OrderDTO> findByUserId(String userId) {
        log.debug("查询用户订单列表，用户ID: {}", userId);
        return orderQueryRepository.findByUserId(userId);
    }
    
    @Override
    public List<OrderDTO> findByConditions(OrderQuery query) {
        log.debug("根据条件查询订单列表，查询条件: {}", query);
        return orderQueryRepository.findByConditions(query);
    }
    
    @Override
    public OrderStatisticsDTO getStatistics(LocalDate startDate, LocalDate endDate) {
        log.debug("获取订单统计信息，开始日期: {}, 结束日期: {}", startDate, endDate);
        return orderQueryRepository.getStatistics(startDate, endDate);
    }
    
    @Override
    public OrderPageResult findByPage(OrderPageQuery pageQuery) {
        log.debug("分页查询订单列表，页码: {}, 每页大小: {}", pageQuery.getPage(), pageQuery.getSize());
        return orderQueryRepository.findByPage(pageQuery);
    }
}